#include "mainwindow.h"

#include <QApplication>
#include <QElapsedTimer>
#include <QSplashScreen>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // app.setQuitOnLastWindowClosed(true);

    // set up application properties
    app.setApplicationDisplayName("v1.0");
    app.setApplicationName("QMarkDown");
    app.setApplicationVersion("version 1.0");
    app.setOrganizationDomain("www.github.com/summychou");
    app.setOrganizationName("Summy Chou");

    QSplashScreen splash(QPixmap::fromImage(QImage(":/material/Ui/loading.png")));
    splash.setDisabled(true);
    splash.show();
    splash.showMessage(QObject::tr("..."), Qt::AlignCenter, Qt::black);

    QElapsedTimer t;
    t.start();
    while(t.elapsed() < 1000) {
        QApplication::processEvents();
    }

    QFile f(":/qss/style.qss");
    if (f.open(QFile::ReadOnly | QFile::Text)) {
        QString styleSheet = f.readAll();
        app.setStyleSheet(styleSheet);
    }
    f.close();

    QTranslator translator;
    if (QLocale::system().name() == "en_US") {
        translator.load(":/qm/qm/qt_en.qm");
    }
    else if (QLocale::system().name() == "zh_CN") {
        translator.load(":/qm/qm/qt_zh_CN.qm");
    }
    else if (QLocale::system().name() == "zh_TW") {
        translator.load(":/qm/qm/qt_zh_TW.qm");
    }
    app.installTranslator(&translator);

    MainWindow w;
    w.show();
    splash.finish(&w);

    return app.exec();
}
